package battlezone;

import java.io.*;
import java.util.*;

class FileManager {

    private static FileManager _instance;
    public File geometryFile;
    public File parameterFile;
    
    public static FileManager getInstance() {
        if (_instance == null) {
            _instance = new FileManager();
        }
        return _instance;
    }

    public FileManager() {

        //FileManager fManager = new FileManager();

        try {
            /*Would like to add some comments to the params files*/
            /*
            String test = "3.2 ''comments here";
            int j = test.indexOf(" ");
            test = test.substring(0, j);
            System.out.println("Here is the substring: " + test);
             */

            // Create a file input stream and Buffered Stream
            //System.out.println(System.getProperty("user.dir"));
            FileReader fileName = new FileReader("resources/config.params");
            BufferedReader bFileName = new BufferedReader(fileName);

            // Create and ArrayList to read file names
            ArrayList<String> al = new ArrayList<String>();
            String fName;
            while ((fName = bFileName.readLine()) != null) {
                al.add(fName);
            }

            // Close file input stream
            fileName.close();
            bFileName.close();

            // Convert al to an Array to use file names
            Object aNames[] = al.toArray();
            if (aNames.length < 2) {
                System.out.println("Error:  The file name count is not correct in file: resources/config.params");
            } else {
            }
            File tParameterFile = new File(aNames[0].toString());
            this.setParameterFile(tParameterFile);
            File tGeometryFile = new File(aNames[1].toString());
            this.setGeometryFile(tGeometryFile);
        } catch (Exception e) {
            System.out.append("Exception: ");
            e.printStackTrace();
            this.setParameterFile(null);
            this.setGeometryFile(null);
        }
    }

    public File getGeometryFile() {
        return geometryFile;
    }

    public void setGeometryFile(File geometryFile) {
        this.geometryFile = geometryFile;
    }

    public File getParameterFile() {
        return parameterFile;
    }

    public void setParameterFile(File parameterFile) {
        this.parameterFile = parameterFile;
    }
}